<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="用户名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺名" prop="shopName">
        <el-input
          v-model="queryParams.shopName"
          placeholder="请输入店铺名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="approvalStatus">
        <dict-select
          :options="dict.type.audit_type"
          v-model="queryParams.approvalStatus"
          placeholder="请选择审核状态"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="baseList">
      <!--      <el-table-column align="center" label="店铺信息"/>-->
      <el-table-column
        label="店铺名称"
        align="left"
        prop="shopName"
        width="160"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="所属用户"
        align="left"
        prop="userName"
        width="120"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="店铺封面"
        align="center"
        prop="shopCoverUrl"
        width="120"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <oss-image-preview :src="scope.row.shopCoverUrl" :width="40" :height="40" />
          <!--          <oss-image-preview :model="'text'" :src="scope.row.shopCoverUrl"/>-->
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="approvalStatus" width="200">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.audit_type" :value="scope.row.approvalStatus" />
        </template>
      </el-table-column>
      <el-table-column
        label="电话"
        align="center"
        prop="phone"
        width="200"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="简介"
        align="left"
        prop="intro"
        width="220"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="邮箱"
        align="center"
        prop="email"
        width="200"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="申请时间"
        align="center"
        prop="createTime"
        width="140"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{m}/{d}/{y}') }}</span>
        </template>
      </el-table-column>
      <!--                <el-table-column label="证件正面照" align="center" prop="cardFrontUrl" width="120" :show-overflow-tooltip="true">
                          <template slot-scope="scope">
                              <oss-image-preview :model="'text'" :src="scope.row.cardFrontUrl" />
                          </template>
                      </el-table-column>
                      <el-table-column label="小店类型" align="center" prop="businessType" width="100" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                          <dict-tag :options="dict.type.store_business_type" :value="scope.row.businessType" />
                        </template>
                      </el-table-column>
                      <el-table-column label="企业名" align="left" prop="companyName" width="120" :show-overflow-tooltip="true" />

                  </el-table-column>
                  <el-table-column align="center" label="个人信息">
                  </el-table-column>
                  <el-table-column label="whatsapp" align="center" prop="whatsapp" width="120" :show-overflow-tooltip="true" />
                  <el-table-column label="telegram" align="center" prop="telegram" width="120" :show-overflow-tooltip="true" />
                  <el-table-column label="审批时间" align="center" prop="approvalTime" width="140" :show-overflow-tooltip="true">
                      <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.approvalTime, '{m}/{d}/{y}') }}</span>
                      </template>
      </el-table-column>-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
        <template slot-scope="scope">
          <span v-if="scope.row.approvalStatus == 0">
            <el-button
              size="mini"
              type="success"
              class="mini-btn"
              plain
              @click="handlePass(scope.row.id)"
            >通过</el-button>
            <el-button
              size="mini"
              class="mini-btn mini-btn-left"
              type="danger"
              plain
              @click="handleUnPass(scope.row.id)"
            >拒绝</el-button>
          </span>
          <span v-else>已审核</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getList, auditPass, auditNoPass } from '@/api/store/entryAudit'
import DateRangePicker from '@/components/DateRangePicker/index.vue'
import OssImagePreview from '@/components/ImagePreview/oss-image-preview.vue'
import Template from '@/views/setting/template/index.vue'

export default {
  name: 'entryAudit',
  components: { Template, DateRangePicker, OssImagePreview },
  dicts: ['audit_type', 'store_business_type'],
  data () {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户小店表格数据
      baseList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      // 查询参数
      queryParams: {
        pageSize: 10,
        pageNum: 1
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          { required: true, message: '用户id不能为空', trigger: 'blur' }
        ]
      },
      dateRange: []
    }
  },
  created () {
    this.getList()
  },
  methods: {
    /** 查询用户小店列表 */
    getList () {
      this.loading = true
      let searchData = this.$deepClone(this.queryParams)
      console.log(!!!this.queryParams.approvalStatus)
      if (!!!this.queryParams.approvalStatus) {//默认查询所有入驻申请
        searchData.approvalStatus = ['0', '1', '2']
      } else {
        searchData.approvalStatus = [searchData.approvalStatus]
      }
      getList(searchData).then(response => {
        let sotreList = response.data.records
        // for (let i = 0; i < sotreList.length; i++) {
        //     const item = sotreList[i];
        //     if (item.status == '0' || item.status == '2') {
        //         item.status = '5'
        //     }
        // }
        this.baseList = sotreList
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1
      this.getList()
    },
    reset () {
      this.queryParams = {
        pageSize: 10,
        pageNum: 1
      }
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    async handlePass (id) {
      this.$confirm('同意当前商铺入驻！', '入驻审核', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(async () => {
        await auditPass(id)
        this.$modal.msgSuccess('审核成功！')
        this.getList()
      }).catch(() => {

      })
    },
    async handleUnPass (id) {
      this.$confirm('拒绝当前商铺入驻！', '入驻审核', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(async ({ value }) => {
        console.log(value)
        await auditNoPass({ shopId: id })
        this.$modal.msgSuccess('拒绝成功！')
        this.getList()
      }).catch(() => {

      })
    }
  }
}
</script>
